package june.handlervontroll;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ProgressBar;
import android.widget.TextView;

public class HandlerControllActivity extends Activity {
    /** Called when the activity is first created. */
	
	public final static int OVERLOAD_START = 0;
	public final static int OVERLOAD_END = 1;
	
	TextView tv;
	Button btn_start;
	Button btn_stop;
	ProgressBar pBar1;
	
	OverloadClass overloadClass;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
        overloadClass = new OverloadClass(getBaseContext(), handler);
        
        tv = (TextView)findViewById(R.id.tv);
        btn_start = (Button)findViewById(R.id.btn_start);
        btn_stop = (Button)findViewById(R.id.btn_stop);
        pBar1 = (ProgressBar)findViewById(R.id.pBar1);
        
        btn_start.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				pBar1.setVisibility(View.VISIBLE);
				overloadClass.Overload(); 
				
			}
		});
        
        btn_stop.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				overloadClass.OverloadStop();
				pBar1.setVisibility(View.INVISIBLE);
			}
		});
    }
    
    Handler handler = new Handler(){

		@Override
		public void handleMessage(Message msg) {
			// TODO Auto-generated method stub
			switch (msg.arg1) {
			
			case OVERLOAD_START:
				
				tv.setText("count : " + msg.arg2);
				
				break;
			
			case OVERLOAD_END:
				pBar1.setVisibility(View.INVISIBLE);
				break;
			
			}
		}
    	
    };
    
}